import Vue from 'vue'
import Router from 'utils/uni-simple-router';
Vue.use(Router);
const whiteList = ['login', 'wxLogin'] // no redirect whitelist
const router = new Router({
	routes: [{
			path: "/pages/public/login",
			name: 'login'
		},
		{
			path: "/pages/public/wechatLogin",
			name: 'wxLogin'
		},
		{
			path: "/pages/public/wechatPhone",
			name: 'wechatPhone'
		},
		{
			path: "/pages/product/product",
			name: 'product'
		},
		{
			path: "/pages/address/address",
			name: 'address'
		},
		{
			path: "/pages/feedBack/feedBack",
			name: 'feedBack'
		},
		{
			path: "/pages/feedBack/feedBackType",
			name: 'feedBackType'
		},
		{
			path: "/pages/userinfo/userinfo",
			name: 'userinfo'
		},
		{
			path: "/pages/index/storeList/storeList",
			name: 'storeList'
		},
		{
			path: "/pages/index/storeSearch/storeSearch",
			name: 'storeSearch'
		},
		{
			path: "/pages/index/storeDetailShop/storeDetailShop",
			name: 'storeDetailShop'
		},
		{
			path: "/pages/index/storeZz/storeZz",
			name: 'storeZz'
		},
		{
			path: "/pages/user/browseRecord/browseRecord",
			name: 'browseRecord'
		},
		{
			path: "/pages/user/collectRecord/collectRecord",
			name: 'collectRecord'
		},
		{
			path: "/pages/user/attentionRecord/attentionRecord",
			name: 'attentionRecord'
		},
		{
			path: "/pages/product/product",
			name: 'product'
		},
		{
			path: "/pages/user/aboutQiHui/aboutQiHui",
			name: 'aboutQiHui'
		},
		{
			path: "/pages/user/personSetting/personSetting",
			name: 'personSetting'
		},{
			path: "/pages/order/orderDetail",
			name: 'orderDetail'
		},{
			path: "/pages/order/createOrder",
			name: 'createOrder'
		},{
			path: "/pages/money/paySuccess",
			name: 'paySuccess'
		},{
			path: "/pages/order/rate/rate",
			name: 'rate'
		},{
			path: "/pages/order/rate/rateSuccess",
			name: 'rateSuccess'
		},{
			path: "/pages/order/rate/rateDetail",
			name: 'rateDetail'
		},{
			path: "/pages/order/billing/billing",
			name: 'billing'
		},{
			path: "/pages/order/order",
			name: 'order'
		},{
			path: "/pages/order/billing/addBill",
			name: 'addBill'
		},{
			path: "/pages/order/billing/addBillType",
			name: 'addBillType'
		},{
			path: "/pages/order/rate/rateList",
			name: 'rateList'
		},{
			path: "/pages/order/logistics",
			name: 'logistics'
		},{
			path: "/pages/order/selfLifing",
			name: 'selfLifing'
		},{
			path: "/pages/cart/cart",
			name: 'cart'
		}
		
		
		
		// {
		// 	path: "/pages/public/wechatLogin",
		// 	name: 'wechatLogin',
		// 	other: {
		// 		H5Name: ''
		// 	},
		// 	beforeEnter: (to, from, next) => {
		// 		to.other.H5Name = to.query.name
		// 		next();
		// 	}
		// }, {
		// 	path: "/pages/router/router2/router2",
		// 	name: 'router2',
		// 	beforeEnter: (to, from, next) => {
		// 		next({
		// 			name: 'router3',
		// 			params: {
		// 				msg: '我是从router2路由拦截过来的'
		// 			}
		// 		});
		// 	}
		// }
	]
});

router.beforeEach((to, from, next) => {
	const token = uni.getStorageSync("token");
	if (token) {
		/* has token */
		next()
	} else {
		if (whiteList.includes(to.name)) {
			// 在免登录白名单，直接进入
			next()
		} else {
			next({
				name: 'wxLogin',
				NAVTYPE: 'push'
			})
		}
	}
})
router.afterEach((to, from) => {
	// console.log(to);
	// console.log(from)
})
// console.log(router)

export default router
